package com.zenith.edu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zenith.edu.mapper.EduStudentGradeMapper;
import com.zenith.edu.po.domain.EduStudentGrade;
import com.zenith.edu.po.dto.EduStudentGradeDTO;
import com.zenith.edu.po.vo.EduStudentGradeVO;
import com.zenith.edu.service.EduStudentGradeService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class EduStudentGradeServiceImpl extends ServiceImpl<EduStudentGradeMapper, EduStudentGrade> implements EduStudentGradeService {
    
    @Override
    public EduStudentGradeVO createStudentGrade(EduStudentGradeDTO dto) {
        EduStudentGrade studentGrade = new EduStudentGrade();
        BeanUtils.copyProperties(dto, studentGrade);
        this.save(studentGrade);
        
        EduStudentGradeVO vo = new EduStudentGradeVO();
        BeanUtils.copyProperties(studentGrade, vo);
        return vo;
    }
    
    @Override
    public EduStudentGradeVO getStudentGradeById(Long id) {
        EduStudentGrade studentGrade = this.getById(id);
        if (studentGrade == null) {
            return null;
        }
        
        EduStudentGradeVO vo = new EduStudentGradeVO();
        BeanUtils.copyProperties(studentGrade, vo);
        return vo;
    }
    
    @Override
    public EduStudentGradeVO updateStudentGrade(EduStudentGradeDTO dto) {
        EduStudentGrade studentGrade = new EduStudentGrade();
        BeanUtils.copyProperties(dto, studentGrade);
        this.updateById(studentGrade);
        
        EduStudentGradeVO vo = new EduStudentGradeVO();
        BeanUtils.copyProperties(studentGrade, vo);
        return vo;
    }
    
    @Override
    public boolean deleteStudentGrade(Long id) {
        return this.removeById(id);
    }
    
    @Override
    public List<EduStudentGradeVO> getStudentGradeList() {
        List<EduStudentGrade> studentGradeList = this.list();
        return studentGradeList.stream().map(studentGrade -> {
            EduStudentGradeVO vo = new EduStudentGradeVO();
            BeanUtils.copyProperties(studentGrade, vo);
            return vo;
        }).collect(Collectors.toList());
    }
}